package Controller;

import Pojo.Customer;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

@Controller
@SessionAttributes(names = {"customer"})
public class CustomerController {

    @RequestMapping(value="/addCustomer",method = RequestMethod.POST)
    public String addCustomer(Customer customer,Model model) {
        model.addAttribute("customer",customer);
        return "forward:toShow";
    }

    @RequestMapping(value = "/toShow")
    public String toShow(){
        return "showCustomer";
    }

    @RequestMapping("/showCustomer")
    public ModelAndView addCustomer(@SessionAttribute("customer") Customer customer, ModelAndView mv){

        mv.addObject("customer",customer);
        mv.setViewName("redirect:/showCustomer");
        return mv;
    }

}